package org.ycx.upms.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ycx.upms.common.constants.SecurityConstants;
import org.ycx.upms.dao.model.SecPermission;
import org.ycx.upms.dao.model.SecUser;
import org.ycx.upms.service.ISecPermissionService;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by 杨 on 2017-06-28.
 */
@Controller
public class HomeController {

    @Value("${app.id}")
    private Integer appId;

    @Autowired
    private ISecPermissionService permissionService;

    @RequestMapping(value = "permissions.thy", method = RequestMethod.GET)
    public @ResponseBody
    List<SecPermission> permissions(HttpSession session) {
        SecUser user = (SecUser) session.getAttribute(SecurityConstants.USER_INFO);
        List<SecPermission> upmsPermissions = this.permissionService.findPermissionByUser(user.getUid(),appId);
        return upmsPermissions;
    }
}
